var add_submit = function(){
	// 再根据条件显示
	var div;
	var sel = $("#bus_type").val();
	switch(sel){
		case "IDC":
			div = "#page_idc";
			break;
		case "专线":
			div = "#page_line";
			break;
		case "集团电话":
			div = "#page_group";
			break;
		case "物联网":
			div = "#page_internet";
			break;
		default:
			break;
	}
	
	var passUrlObj = {
		"id":$("#id").val(),
		"bus_type":$("#bus_type").val(),
		"operator":$("#operator").val(),
		"group_name":$("#group_name").val(),
		"group_no":$("#group_no").val(),
		"k1":$(div + " #k1").val(),
		"k2":$(div + " #k2").val(),
		"k3":$(div + " #k3").val(),
		"k4":$(div + " #k4").val(),
		"k5":$(div + " #k5").val(),
		"k6":$(div + " #k6").val(),
		"k7":$(div + " #k7").val(),
		"k8":$(div + " #k8").val()
	};

	var params = passUrlObj;
	$.ajax({
		type: "post",
		data: params,
		url: "../../../opponent/editIdc",
		dataType: "json",
		async: true,
		success: function(data) {
			console.log(data);
			if(data.resultCode!=1000){
				showErrorMsg(data.message);
				console.log("修改失败！code:"+data.message);
				return;
			}
			$("#submit_success").click();
		},
		error : function(textStatus) {
			showErrorMsg("修改数据失败！服务器没有返回。");
			disabled_submit_button(false);
			console.log("修改数据失败！服务器没有返回。");
		}
	});
}
var showErrorMsg = function(msg){
	$("#err_msg_info").html(msg);
	$("#submit_error").click();
}

var hideDiv = function(){
	// 全部隐藏
	$("#page_idc").hide();
	$("#page_line").hide();
	$("#page_group").hide();
	$("#page_internet").hide();
}

var showOpponentData = function(data){
	hideDiv();
	//var data = JSON.parse(decodeURIComponent(getParamValue("idcdata")));
	
	// 初始化START
	var div;
	var busType = data.bus_type;
	switch(busType){
		case "IDC":
			div = "#page_idc";
			$("#page_idc").show();
			break;
		case "专线":
			div = "#page_line";
			$("#page_line").show();
			break;
		case "集团电话":
			div = "#page_group";
			$("#page_group").show();
			break;
		case "物联网":
			div = "#page_internet";
			$("#page_internet").show();
			break;
		default:
			break;
	}
	
	$("#id").val(data.id);
	$("#group_name").val(data.group_name);
	$("#group_no").val(data.group_no);
	$("#bus_type").find("option[value='"+data.bus_type+"']").attr("selected",true);
	$("#operator").find("option[value='"+data.operator+"']").attr("selected",true);
	if(busType == "专线" || busType == "物联网"){
		$(div + " #k1").find("option[value='"+data.k1+"']").attr("selected",true);
	}else{
		$(div + " #k1").val(data.k1);
	}
	$(div + " #k2").val(data.k2);
	$(div + " #k3").val(data.k3);
	$(div + " #k4").val(data.k4);
	$(div + " #k5").val(data.k5);
	$(div + " #k6").val(data.k6);
	$(div + " #k7").val(data.k7);
	$(div + " #k8").val(data.k8);
	// 初始化END
	
	// 显示 隐藏 新增界面
	$("#bus_type").on('change', function() {
		// 先全部隐藏
		hideDiv();
		
		// 再根据条件显示
		var sel = $("#bus_type").val();
		switch(sel){
			case "IDC":
				$("#page_idc").show();
				break;
			case "专线":
				$("#page_line").show();
				break;
			case "集团电话":
				$("#page_group").show();
				break;
			case "物联网":
				$("#page_internet").show();
				break;
			default:
				break;
		}
	});
};



var back_list = function(){
	window.location.href = "javascript:history.go(-1);";
}
var disabled_submit_button = function(open){
		if(open){
			$("#submit_wite").click();
			$("#add_submit").html(" <img width='20px;' src='../../../img/progress.gif'> 提交中...");
			$("#add_submit").attr("disabled","disabled");
		}else{
			$("#wite_close").click();
			$("#add_submit").html("提交");
			$("#add_submit").removeAttr("disabled");
		}
};

$(function(){
    id = getParamValue("id");
    console.log("id="+id);
    $.ajax({
      type: "post",
      contentType: "application/json",
      url: "../../../opponent/getIdcDetailsById?id=" + id,
      dataType: "json",
      async: true,
      success: function(data) {
        if (data.resultCode != 1000) {
          console.log("接口返回失败！code:" + data.message);
          return;
        }
        $("#modal-loading").modal('close');
        showOpponentData(data.data);
      },
      error: function(textStatus) {
        $("#modal-loading").modal('close');
        showBottomMsg("获取信息失败！");
        console.info("request error:");
      }
    });
  });
